package com.molin.conllectionTest;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class lianxi01 {
    //使用Collection存储学生信息，并遍历(迭代器方式)。
    public static void main(String[] args) {
        Collection<Student> collection=new ArrayList<Student>();
        collection.add(new Student("小皮",23));
        collection.add(new Student("小贾",23));
        collection.add(new Student("小路",23));
        Iterator iterator=collection.iterator();
        while (iterator.hasNext()) {
           String studentInfo =iterator.next().toString();
            System.out.println(studentInfo);
        }

        System.out.println("-----------------------");
        for (Student student : collection) {
            System.out.println(student.toString());
        }
    }
}

class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}